//
//  WePersonalHeaderInfoView.m
//  WeGalaxy
//
//  Created by Zheng on 2017/7/6.
//  Copyright © 2017年 Zheng. All rights reserved.
//

#import "WePersonalHeaderInfoView.h"
#import "WePersonalInfoControl.h"

@implementation WePersonalHeaderInfoView

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    
    UITouch *touch = touches.allObjects.lastObject;
    CGPoint point = [touch locationInView:self];
    
    if (point.y <= 55) {
        _setIconBlock();
    }
    
}

#pragma mark - 点击事件
- (void)ctrlClickAction:(UIControl *)sender {
    
    WePersonalInfoControlClickType type = WePersonalInfoControlClickTypeBePraised;
    
    if (sender == _bePraisedCtrl) {
        type = WePersonalInfoControlClickTypeBePraised;
    } else if (sender == _focusOnCtrl) {
        type = WePersonalInfoControlClickTypeFocusOn;
    } else {
        type = WePersonalInfoControlClickTypeFans;
    }
    
    _infoCtrlBlock(type);
}

#pragma mrak - 初始化
- (instancetype)init {
    self = [super init];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self subviewInView];
    }
    
    return self;
}

#pragma mark - 子视图
- (void)subviewInView {
    [self addSubview:self.nameLbl];
    [self addSubview:self.iconImgv];
    [self addSubview:self.lineView];
    [self addSubview:self.accessoryBtn];
    [self addSubview:self.bePraisedCtrl];
    [self addSubview:self.focusOnCtrl];
    [self addSubview:self.fansCtrl];
    [self addSubview:self.bLineView];

    [_nameLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(30);
        make.top.mas_equalTo(20);
    }];
    
    [_accessoryBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_nameLbl);
        make.right.mas_equalTo(-20);
        make.width.height.mas_equalTo(30);
    }];
    
    [_iconImgv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(_accessoryBtn.mas_left).offset(-10);
        make.width.height.mas_equalTo(40);
        make.centerY.equalTo(_nameLbl);
    }];
    
    [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_nameLbl.mas_bottom).offset(15);
        make.left.mas_equalTo(27);
        make.right.mas_equalTo(-20);
        make.height.mas_equalTo(0.5);
    }];
    
    [_bePraisedCtrl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(70);
        make.left.mas_equalTo(15);
        make.top.equalTo(_lineView.mas_bottom).offset(3);
    }];
    
    [_focusOnCtrl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.width.height.equalTo(_bePraisedCtrl);
        make.centerX.equalTo(self);
    }];
    
    [_fansCtrl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.width.height.equalTo(_bePraisedCtrl);
        make.right.mas_equalTo(-15);
    }];
    
    [_bLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self);
        make.height.mas_equalTo(0.5);
    }];
}

- (UILabel *)nameLbl {
    if (!_nameLbl) {
        _nameLbl = [UILabel new];
        _nameLbl.text = @"罗力";
        _nameLbl.font = kCX_FONT(19);
    }
    return _nameLbl;
}

- (UIImageView *)iconImgv {
    if (!_iconImgv) {
        _iconImgv = [[UIImageView alloc] init];
        kCX_RADIUS(_iconImgv, 20, 0);
        _iconImgv.layer.backgroundColor = [[UIColor orangeColor] CGColor];
    }
    return _iconImgv;
}

- (UIButton *)accessoryBtn {
    if (!_accessoryBtn) {
        _accessoryBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_accessoryBtn setImage:kIMAGE(@"acc") forState:UIControlStateNormal];
        _accessoryBtn.userInteractionEnabled = NO;
    }
    return _accessoryBtn;
}

- (UIView *)lineView {
    if (!_lineView) {
        _lineView = [UIView new];
        _lineView.backgroundColor = kRGB_COLOR(200, 199, 204, 1);
    }
    return _lineView;
}

- (WePersonalInfoControl *)bePraisedCtrl {
    if (!_bePraisedCtrl) {
        _bePraisedCtrl = [self getInfoCtrl:@"被赞数"];
        _bePraisedCtrl.redView.hidden = YES;
    }
    return _bePraisedCtrl;
}

- (WePersonalInfoControl *)focusOnCtrl {
    if (!_focusOnCtrl) {
        _focusOnCtrl = [self getInfoCtrl:@"关注数"];
        _focusOnCtrl.redView.hidden = YES;
    }
    return _focusOnCtrl;
}

- (WePersonalInfoControl *)fansCtrl {
    if (!_fansCtrl) {
        _fansCtrl = [self getInfoCtrl:@"粉丝数"];
        _fansCtrl.numbersLbl.text = @"14";
    }
    return _fansCtrl;
}

- (WePersonalInfoControl *)getInfoCtrl:(NSString *)title {
    WePersonalInfoControl *ctrl = [[WePersonalInfoControl alloc] init];
    ctrl.titleLbl.text = title;
    [ctrl addTarget:self action:@selector(ctrlClickAction:) forControlEvents:UIControlEventTouchUpInside];
    return ctrl;
}

- (UIView *)bLineView {
    if (!_bLineView) {
        _bLineView = [UIView new];
        _bLineView.backgroundColor = kRGB_COLOR(200, 199, 204, 1);
    }
    return _bLineView;
}



@end
